package com.fuershiye.woman.monitor.constants;

import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.common.collect.Lists;

public enum Plat {
	ALL(-1, "全平台",-1),
    AndroidPad(0, "android Pad",1),
    iPad(1, "iPad",2),
    iPhone(3, "iPhone",4),
    AndroidPhone(6, "android Phone",8),
    AndroidTV(10, "android TV",16),
    WindowsPhone(11, "windows Phone",32),
    PC(18, "PC",64),
    WeChatH5(19, "微信H5",128),
    H5(1000, "H5",256);

    private final Integer code;
    private final String name;
    private final Integer realCode;

    private static final Map<Integer,Plat> lookupByCode=new HashMap<Integer, Plat>();
    private static final Map<Integer,Plat> lookupByRealCode=new HashMap<Integer, Plat>();

    static {
        for(final Plat p: EnumSet.allOf(Plat.class)){
            lookupByCode.put(p.getCode(),p);
            lookupByRealCode.put(p.getRealCode(),p);
        }
    }


    Plat(Integer code, String name, Integer realCode) {
        this.code = code;
        this.name = name;
        this.realCode = realCode;
    }

    public Integer getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public Integer getRealCode() {
        return realCode;
    }


    public static Plat getPlatByCode(int code){
        return lookupByCode.get(code);
    }
    
    public static Plat getPlatByRealCode(int realCode){
        return lookupByRealCode.get(realCode);
    }

    public static boolean contains(int plat) {
        for (Plat p :values()){
            if (p.getCode()==plat){
                return true;
            }
        }
        return false;
    }


    public static List<Plat> findPlat(int plat){
        List<Plat> plats = Lists.newArrayList();
        plats.remove(ALL);
        for (Plat p :values()){
            if ((p.getRealCode()&plat)==p.getRealCode()){
                plats.add(p);
            }
        }
        return plats;
    }
    
}
